package carmensd.vista

import org.uqbar.arena.aop.windows.TransactionalDialog
import org.uqbar.arena.layout.HorizontalLayout
import org.uqbar.arena.layout.VerticalLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.List
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.TextBox
import org.uqbar.arena.windows.WindowOwner
import applicationModel.EditarCaracteristicasAppModel

class EditarCaracteristicasWindow extends TransactionalDialog<EditarCaracteristicasAppModel>{
	
	new(WindowOwner owner, EditarCaracteristicasAppModel model) {
		super(owner, model)
	}
	
	override protected createFormPanel(Panel panel) {
		this.setTitle = "Editar caracteristicas de: " + this.getModelObject.pais.nombre
		panel.setLayout(new VerticalLayout())
		
		colocarLista(panel, "pais.caracteristicas", "caracteristicaElegida")
		
		new Button(panel) => [
			caption = "Eliminar";
			onClick [|this.modelObject.eliminarCaracteristica()];
		]
		
		this.componentesParaAgregar(panel)
		
		new Button(panel) => [
			caption = "Aceptar";
			onClick [|this.cerrarVentana()];
		]
	}
	
	def cerrarVentana() {
		this.close()
	}
	
	
	def componentesParaAgregar(Panel panel) {
		var Panel panelAgregado = new Panel(panel);
		panelAgregado.setLayout(new HorizontalLayout())
		
		new TextBox(panelAgregado).bindValueToProperty("caracteristicaAgregar")
		new Button(panelAgregado) => [
			caption = "Agregar"
			onClick[| this.modelObject.agregarCaracteristica()]
		]
		
	}
	
	def colocarLista(Panel nuevoVillanoPanel, String propiedadDelDominio, String propiedad) {
			new List(nuevoVillanoPanel) => [
				width = 90
				height = 90
				allowNull(true)
				bindItemsToProperty(propiedadDelDominio)
				bindValueToProperty(propiedad)
			]
	}
	
}